package com.zzyl.nursing.controller.member;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.ElderFamilyPage;
import com.zzyl.nursing.dto.AddFamilyDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DataVo;
import com.zzyl.nursing.vo.DeviceShadowVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.QueryFamilyVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;

/**
 * 老人家属Controller
 * 
 * @author chenxin
 * @date 2025-08-01
 */
@Tag(name = "老人家属")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IDeviceService deviceService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }
    //绑定老人
    @PostMapping("/add")
    public AjaxResult addFamily(@RequestBody AddFamilyDto dto){
        familyMemberService.addFamily(dto);
        return success();
    }

    //查询家人列表
    @GetMapping("/my")
    public R<List<QueryFamilyVo>> queryFamily(){
        List<QueryFamilyVo> list = familyMemberService.queryFamily();
        return R.ok(list);
    }

    //分页查询
    @GetMapping("/list-by-page")
    public AjaxResult queryFamilyPage(Integer pageNum,Integer pageSize){
        List<ElderFamilyPage> list = familyMemberService.queryFamilyPage(pageNum, pageSize);
        return AjaxResult.success(list);
    }

    //健康数据
    @GetMapping("/queryServiceProperties/{iotId}")
    public R getDeviceData(@PathVariable String iotId){
        List<DeviceShadowVo> deviceShadowVos = deviceService.queryServiceProperties(iotId);
        return R.ok(deviceShadowVos);
    }

    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(String iotId, String functionId, Long startTime, Long endTime){
        List<DataVo> dataVoList = familyMemberService.queryDeviceDataListByDay(iotId,functionId,startTime,endTime);
        return AjaxResult.success(dataVoList);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(String iotId, String functionId, Long startTime, Long endTime){
        List<DataVo> dataVoList = familyMemberService.queryDeviceDataListByWeek(iotId,functionId,startTime,endTime);
        return AjaxResult.success(dataVoList);
    }
}
